package com.td.module.equipment.dal.mysql.info;

import com.td.framework.common.pojo.PageResult;
import com.td.framework.mybatis.core.mapper.BaseMapperX;
import com.td.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.td.module.equipment.controller.admin.info.vo.InfoExportReqVO;
import com.td.module.equipment.controller.admin.info.vo.InfoPageReqVO;
import com.td.module.equipment.dal.dataobject.info.InfoDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 设备信息 Mapper
 *
 * @author 王翔翔
 */
@Mapper
@Repository("equipmentInfoMapper")
public interface InfoMapper extends BaseMapperX<InfoDO> {

    default PageResult<InfoDO> selectPage(InfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InfoDO>()
                .eqIfPresent(InfoDO::getStationId, reqVO.getStationId())
                .betweenIfPresent(InfoDO::getMonitorTime, reqVO.getMonitorTime())
                .eqIfPresent(InfoDO::getVolt, reqVO.getVolt())
                .eqIfPresent(InfoDO::getRssi, reqVO.getRssi())
                .eqIfPresent(InfoDO::getImei, reqVO.getImei())
                .eqIfPresent(InfoDO::getLongitude, reqVO.getLongitude())
                .eqIfPresent(InfoDO::getLatitude, reqVO.getLatitude())
                .eqIfPresent(InfoDO::getDotled, reqVO.getDotled())
                .eqIfPresent(InfoDO::getControlOp, reqVO.getControlOp())
                .eqIfPresent(InfoDO::getVersion, reqVO.getVersion())
                .eqIfPresent(InfoDO::getIsOnline, reqVO.getIsOnline())
                .eqIfPresent(InfoDO::getType, reqVO.getType())
                .betweenIfPresent(InfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InfoDO::getId));
    }

    default List<InfoDO> selectList(InfoExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<InfoDO>()
                .eqIfPresent(InfoDO::getStationId, reqVO.getStationId())
                .betweenIfPresent(InfoDO::getMonitorTime, reqVO.getMonitorTime())
                .eqIfPresent(InfoDO::getVolt, reqVO.getVolt())
                .eqIfPresent(InfoDO::getRssi, reqVO.getRssi())
                .eqIfPresent(InfoDO::getImei, reqVO.getImei())
                .eqIfPresent(InfoDO::getLongitude, reqVO.getLongitude())
                .eqIfPresent(InfoDO::getLatitude, reqVO.getLatitude())
                .eqIfPresent(InfoDO::getDotled, reqVO.getDotled())
                .eqIfPresent(InfoDO::getControlOp, reqVO.getControlOp())
                .eqIfPresent(InfoDO::getVersion, reqVO.getVersion())
                .eqIfPresent(InfoDO::getIsOnline, reqVO.getIsOnline())
                .eqIfPresent(InfoDO::getType, reqVO.getType())
                .betweenIfPresent(InfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InfoDO::getId));
    }
    Integer sumInfo();
}
